/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/16 11:31
 * @Copyright
 */
package JDBC;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCtest2 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try {
            //1、注册驱动
            DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            //2、获得连接
            conn = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/base1?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC",
                    "root",
                    "123456");
            //3、获得数据库操作对象
            stmt = conn.createStatement();
            //4、执行SQL语句
            //String sql="update user set username='海东哥'where id='1'";
            String sql = "delete from user where username='jack'";
            int count = stmt.executeUpdate(sql);
            System.out.println(count == 1 ? "修改成功！" : "修改失败！");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

